﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZK.Common;

namespace ZK.YCGLRD_TransManage
{
    public partial class Index : Form
    {
        private WFAutoSizeHelper wFAutoSizeHelper = new WFAutoSizeHelper();
        public Index()
        {
            InitializeComponent();
            wFAutoSizeHelper.GetAllInitInfo(this.Controls[0], this);
            this.StartPosition = FormStartPosition.CenterScreen;

            HideShowMenu();

            labelLCw.Text = IConfig.GetSetuserInfo.LoginAccount;
        }

        /// <summary>
        /// 显示隐藏相关的菜单列表
        /// </summary>
        private void HideShowMenu()
        {
            string item = AppConfigHelper.GetAppSettings("MenuItem");
            var itemArr = item.Split(',');
            foreach (var i in item)
            {
                if (i == '1')
                {
                    this.buttonWeaglenTest.Visible = true;
                }
                if (i == '2')
                {
                    this.buttonPrintPoundList.Visible = true;
                }
                if (i == '3')
                {
                    this.button1.Visible = true;
                }
                if (i == '4')
                {
                    this.button2.Visible = true;
                }

            }
        }

        /// <summary>
        /// 窗口变化事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            if (wFAutoSizeHelper.ControlsInfo.Count > 0)//如果字典中有数据，即窗体改变
            {
                wFAutoSizeHelper.ControlsChangeInit(this.Controls[0]);//表示pannel控件
                wFAutoSizeHelper.ControlsChange(this.Controls[0]);
                Common.DelegateHelper.SendWidthHeightEvent?.Invoke(this.Controls[0].Width, this.Controls[0].Height);
            }
        }

        /// <summary>
        /// 改变左边菜单栏样式
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="button"></param>
        private void ChangeStyle(Panel panel, object button)
        {
            var ct = panel.Controls;
            foreach (Button item in ct)
            {
                item.BackColor = Color.White;
                item.ForeColor = Color.Black;
            }
            ((Button)button).BackColor = Color.Black;
            ((Button)button).ForeColor = Color.White;

            //wFAutoSizeHelper.GetAllInitInfo(this.Controls[0], this);
            DelegateHelper.SendWidthHeightEvent?.Invoke(this.Controls[0].Width, this.Controls[0].Height);
        }

        /// <summary>
        /// 地磅检测按钮-wagonBalance
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button3_Click(object sender, EventArgs e)
        {
            panelContent.Controls.Clear();
            UC.WagonBalance wagonBalance = new UC.WagonBalance
            {
                Parent = panelContent,
                Dock = DockStyle.Fill
            };

            var ct = panelMenu.Controls;
            ChangeStyle(panelMenu, sender);


        }

        /// <summary>
        /// PrintPoundList  门卫打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button4_Click(object sender, EventArgs e)
        {
            //panelContent.Controls.Clear();
            //YCGLRD_TransManage.UC.PrintPoundListTest printPoundList = new YCGLRD_TransManage.UC.PrintPoundListTest
            //{
            //    Parent = panelContent,
            //    Dock = DockStyle.Fill
            //};
            //printPoundList.Show();
            //var ct = panelMenu.Controls;
            //ChangeStyle(panelMenu, sender);

            UC.PrintPoundListTest printPoundListTest = new UC.PrintPoundListTest();
            printPoundListTest.Show();
        }

        /// <summary>
        /// cancel button event
        /// 注销
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button2_Click(object sender, EventArgs e)
        {
            //注销
            this.Hide();
            Login login = new Login();
            login.Show();
        }

        /// <summary>
        /// closed event  关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Index_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        /// <summary>
        /// reset 重启
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonReset_Click(object sender, EventArgs e)
        {

            if (MessageBox.Show("重新启动？", "提示", MessageBoxButtons.YesNoCancel,
                MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Thread.Sleep(1000);
                Application.Restart();
            }



        }

        /// <summary>
        /// 出厂入厂
        /// in out
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button1_Click(object sender, EventArgs e)
        {
            panelContent.Controls.Clear();
            YCGLRD_TransManage.UC.InOut printPoundList = new YCGLRD_TransManage.UC.InOut
            {
                Parent = panelContent,
                Dock = DockStyle.Fill
            };
            printPoundList.Show();
            var ct = panelMenu.Controls;
            ChangeStyle(panelMenu, sender);


        }

        /// <summary>
        /// 室内读卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button2_Click_1(object sender, EventArgs e)
        {
            panelContent.Controls.Clear();
            YCGLRD_TransManage.UC.SNReader printPoundList = new YCGLRD_TransManage.UC.SNReader
            {
                Parent = panelContent,
                Dock = DockStyle.Fill
            };
            printPoundList.Show();
            var ct = panelMenu.Controls;
            ChangeStyle(panelMenu, sender);
        }
    }
}
